package com.probiz.estoresa.inventory.web.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;

import com.probiz.estore.common.model.inventory.InventoryAudit;
import com.probiz.estore.common.model.product.ProductSku;
import com.probiz.estore.core.controller.GenericStoreAdminController;
import com.probiz.estore.core.search.SearchCriteria;
import com.probiz.estore.inventory.service.InventoryAuditManager;
import com.probiz.estore.product.service.ProductSkuManager;
import com.probiz.estore.webapp.util.RequestUtil;

public class InventoryAuditController extends GenericStoreAdminController<InventoryAudit> {
    private InventoryAuditManager inventoryAuditManager = null;
    private ProductSkuManager productSkuManager = null;

    public void setInventoryAuditManager(InventoryAuditManager inMgr) {
        this.inventoryAuditManager = inMgr;
    }

	public void setProductSkuManager(ProductSkuManager productSkuManager) {
		this.productSkuManager = productSkuManager;
	}


	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.core.controller.GenericController#getEntityName(java.lang.Object)
	 */
	@Override
	protected String getEntityName(InventoryAudit entity) {
		return entity.getProductSku().getProductSkuCode();
	}


	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.core.controller.BaseController#initController()
	 */
	@Override
	protected void initController() throws Exception {
		mgr = inventoryAuditManager;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.core.controller.GenericController#preSave(javax.servlet.http.HttpServletRequest,
	 *      java.lang.Object, org.springframework.validation.BindException)
	 */
	@Override
	protected void preSave(HttpServletRequest request, InventoryAudit entity, BindException errors) {
	}
	
	
	public ModelAndView defaultAction(HttpServletRequest request,HttpServletResponse response) {
		return search(request, response);
	}
	
	public ModelAndView search(HttpServletRequest request,HttpServletResponse response) {
		ModelAndView mv = new ModelAndView("inventory/inventoryAuditList");
		ProductSku productSku = productSkuManager.getById(RequestUtil.getInteger(request,"productSkuId"));
		mv.addObject("productSku",productSku);
		
		//start:查询
		this.setLastSearchViewAllowed(false);
		SearchCriteria sc = createSearchCriteria(request, InventoryAudit.FilterHqlName.FIND_BY_PRODUCTSKUID);
		sc.addParamValue(productSku.getProductSkuId());
		List<InventoryAudit> inventoryAuditList = searchByCriteria(sc);
		//end:查询
		mv.addObject("inventoryAuditList",inventoryAuditList);
		return mv;
	}

}
